package org.hxzon.cyclone.pfgen;

import org.hxzon.cyclone.Particle;
import org.hxzon.cyclone.Vector3;
//pfgen.h,pfgen.cpp
//绳索（蹦极），只有拉力，没有张力，其中一点固定

public class ParticleAnchoredBungee extends ParticleAnchoredSpring {

    public void updateForce(Particle particle, double duration) {
        // Calculate the vector of the spring
        Vector3 force = particle.getPosition().copy();
        force.minusUpdate(anchor);

        double magnitude = force.magnitude();
        if (magnitude < restLength) {
            return;
        }
        magnitude = magnitude - restLength;

        magnitude *= springConstant;
        force.normalise();
        force.multiUpdate(-magnitude);
        particle.addForce(force);
    }

}
